#ifndef _GRPCACCESS_H_
#define _GRPCACCESS_H_

#include "config.h"

#include <buildspec.h>
#include <GSTenums.h>
#include <Client/ClientUtils/Network/NetworkInterface.h>
#include <Client/ClientUtils/Network/AbstractRDBAccess.h>

#include <cstdint>

namespace GST {
namespace ClientUtils {

class GST_API_EXPORT GRPCAccess
	: public NetworkInterface
{
public:

	GRPCAccess(HostPtr host);
	~GRPCAccess();

	virtual bool isConnected() const;

	virtual void connect();

	virtual void disconnect();

	virtual bool isSSLUsed() const;

	virtual NetworkPtr fork() const;

	virtual NetworkPtr reconnect(const std::string & user, const std::string & pwd, const std::string & db="") const;

	virtual bool isSuperUserConnection() const;

	virtual UserPtr getCurrentGSTUser() const;

	virtual std::string getEndPointName() const;

	virtual std::string getUserName() const;

	virtual EndPointPtr getEndPoint() const;

	virtual BackendType GetBackendType() const;

	virtual ServerInfoPtr GetServerInformation();

	virtual DataTablePtr GetServerInformationTable() const;

	virtual bool TableIsSelectable(const std::string & fullTableName) const;

	virtual bool ColumnExistInTable(const std::string & fullTableName, const std::string & columnName) const;

	virtual NamesListPtr ListAllTables() const;

	virtual NamesListPtr ListAllColumns(const std::string& tablename) const;

	virtual NamesListPtr ListPrimaryKeyColumns(const std::string& tablename) const;

	virtual bool ViewRefersTable(const std::string& tablename, const std::string& viewname) const;

	virtual NamesListPtr ListAllViewsRefersTable(const std::string& tablename) const;

	virtual std::string GetExactColumnDataType(const std::string& columnname) const;

	virtual ClientUtils::TableAttributeDesc::DType GetColumnDType(const std::string& columnname) const;

	virtual ConstrainedTableAttributeValArrayPtr GetConstrainedPropertyValues(const TableAttributeDesc& cp);

	virtual FeatureClassDescListPtr ListFeatureClasses();
	virtual FeatureClassDetailedDescListPtr ListFeatureClassesDetailed() const;

	virtual int CountFeatures(const FeatureClassDesc& featureClass) const;

	virtual AssignableFeatureDescListPtr ListAllFeatures(const FeatureClassDesc& featureClass) const;

	virtual TableConstrainedAttributeDescPtr UpdateConstrainedPropertyDesc(const TableConstrainedAttributeDesc & cp) const;

	virtual GeoColumnDescPtr GetGeoColumnDesc(const FeatureClassDesc& featureClass) const;

	virtual FeatureDescPtr GetFeatureDescByGeomId(const long & idgeo) const;

	virtual FeatureDescPtr GetFeatureDescByLockId(const std::string & lockid) const;

	virtual SimplexPropertyDescListPtr GetSimplexPropertyList(const FeatureClassDesc& featureClass) const;

	virtual ObjectPropertyDescListPtr GetObjectPropertyList(const FeatureClassDesc& featureClass , bool filterMemberProperties = true) const;

	virtual NamesListPtr ListConstrainedProperties(const FeatureClassDesc& featureClass, bool IsObject) const;

	virtual ConstrainedObjectPropertyDescPtr GetConstrainedObjectProperty(const FeatureClassDesc& featureClass, const std::string propertyName) const;

	virtual ConstrainedSimplexPropertyDescPtr GetConstrainedSimplexProperty(const FeatureClassDesc& featureClass, const std::string propertyName) const;

	virtual ObjectPropertiesByIdgeoMapPtr GetObjectPropertyValuesOfFeatureClass(const FeatureClassDesc & featureClass, const TableAttributeDescList& selection=TableAttributeDescList() ) const;

	virtual TableAttributeValListPtr GetObjectPropertyValues(const FeatureDesc & feature, const TableAttributeDescList& selection=TableAttributeDescList() ) const;

	virtual void CreateTable(const GST::ClientUtils::TableAttributeDescList & attributes , bool quoteTablename = true);

	virtual void DropTable(const std::string & tableName , bool quoteTablename = true);

	virtual void InsertRecord(const GST::ClientUtils::TableAttributeValList & attributes, bool quoteTablename = true);
	virtual void DeleteRecord(const GST::ClientUtils::TableAttributeVal &attribute,
					  bool quoteTablename = true) const override;

	virtual DataTablePtr GetTableValues(const std::string & tablename, const TableAttributeDescList & selection = TableAttributeDescList() , const std::string & filter = std::string() ) const;

	virtual void UpdateTableValues(RecordPtr record);
	virtual void UpdateTableValuesInternal(RecordPtr record);

	virtual void UpdateObjectPropertyValue(const FeatureDesc & feature, const TableAttributeVal& value);

	virtual void UpdateObjectPropertyValue(const FeatureDesc & feature, const ConstrainedTableAttributeVal& value);

	virtual void UpdateObjectPropertyValues( const FeatureDesc & feature, const TableAttributeValList& values );

	virtual FeatureClassDescPtr RenameFeatureClass(FeatureClassDetailedDesc& featureClassDesc, const std::string& newName);
	virtual FeatureClassDescPtr ChownFeatureClass(
		const FeatureClassDesc &featureClassDesc,
		const Owner &newOwner,
		const std::string &newName = std::string()) const override;
	virtual FeatureClassDescPtr CreateFeatureClassSnapshot(
		const FeatureClassDesc &sourceFeatureClass,
		const Owner &owner,
		const std::string &name,
		const std::string &commitMessage) const override;
	virtual std::pair<FeatureClassDescPtr, FeatureDescListPtr>
	CreateFeatureSelectionSnapshot(
		const FeatureDescListPtr &features,
		const Owner &owner,
		const std::string &name,
		const std::string &commitMessage,
		const boost::optional<AreaLimiter> &areaLimiter
		= boost::none) const override;

	virtual void CreatePropertyTable(const FeatureClassDesc& featureClass, const GeoColumnDesc & geocolumn);

	virtual void AppendObjectProperty(const FeatureClassDesc& featureClass, const TableAttributeDesc& attribute);

	virtual void AppendSimplexProperty(const FeatureClassDesc& featureClass, const TableAttributeDesc& attribute);

	virtual void AppendConstrainedObjectProperty(const FeatureClassDesc& featureClass, const ConstrainedObjectPropertyDesc& attribute);

	virtual void AppendConstrainedSimplexProperty(const FeatureClassDesc& featureClass, const ConstrainedSimplexPropertyDesc& attribute);

	virtual void RenameProperty(const FeatureClassDesc& featureClass, TableAttributeDescPtr attribute, const std::string& newName) const;

	virtual void DeleteConstrainedProperty(const FeatureClassDesc& featureClass, const std::string propertyName, const bool isObjectProp = true);

	virtual void DeleteProperty(const FeatureClassDesc& featureClass, const std::string propertyName, bool isObjectProp = true);

	virtual void SimplifyFeature(const FeatureDesc & feature);

	virtual void DeleteFeature(long id) const;

	virtual void DeleteFeatureClass(const std::string & featureClassName);
	virtual void DeleteFeatureClass(const FeatureClassDesc & featureClass);

	virtual CrudeFeaturePtr GetFeature(const FeatureDesc & feature , const Geometry::IGeometry::RequestFormat & geometryformat, Geometry::SRSPtr srs, bool lock = false, QueryBoxPtr queryBox = QueryBoxPtr() , long commitKey = -1 );
	virtual CrudeFeaturePtr GetFeature(
		const FeatureDesc &feature,
		const Geometry::IGeometry::RequestFormat &geometryformat,
		Geometry::SRSPtr srs,
		const boost::optional<AreaLimiter> &areaLimiter,
		bool lock = false,
		long commitKey = -1) override;

	virtual CrudeFeaturePtr GetFeatureBinary(const FeatureDesc & feature, Geometry::SRSPtr srs, QueryBoxPtr queryBox = QueryBoxPtr() , long commitKey = -1);

	virtual FeatureDescPtr UploadNewFeatureFromMemory(const Geometry::StreamableGeometry & feature, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

	virtual FeatureDescPtr UploadNewFeature(const Geometry::StreamableGeometry & feature, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

	virtual void UpdateFeatureFromMemory(const Geometry::StreamableGeometry & feature, const std::string & lockid, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

	virtual void UpdateFeature(const Geometry::StreamableGeometry & feature, const std::string & lockid, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

	virtual void InstantUpdateFeature(const Geometry::StreamableGeometry & feature, const long& idgeo, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

	virtual void UpdateFeatureKeepLock(const Geometry::StreamableGeometry & feature, const std::string & lockid, const FeatureClassDesc & target, long commitKey = -1, bool updateStats = true);

    void
    UpdateFeature_impl( const Geometry::StreamableGeometry & feature, const std::string & lockid, bool keepLock, const FeatureClassDesc & target, long commitKey, bool updateStats /*= true*/ );

	virtual void MoveFeature(const FeatureDesc& feature, const FeatureClassDesc& target, const std::string& targetfeaturename = "");

	virtual void UnlockByKey(const std::string & key);

	virtual std::string LockGeometry(long idgeo);

	virtual LockInfoListPtr GetLockInfo(long idgeo) const;

	virtual void ExecuteScript(const std::string & script);

	virtual AbstractRDBAccess * RDBAccess();

    virtual std::vector<unsigned char> GetColorsFromIdx(const long& idgeo,
                                                        const std::string& property,
                                                        const std::string& vrtxIdxList,
                                                        const ColorMap::Id &colorMapId) const;
	// For BinaryGeometry
	void WritePropertyColors(const long &idgeo,
							 const std::string &property,
							 const ColorMap::Id &colorMapId,
							 const std::string &filePath) const;
	// For PopGeometry
    void GetColorsFromIdx(const long& idgeo,
                          const std::string& property,
                          const ColorMap::Id &colorMapId,
                          const std::string &path,
                          const FeatureDesc &feature,
                          const Geometry::SRSPtr srs) const;

	virtual void WriteGridSlices(long idgeo,
								 const std::string &propertyName,
								 long colorMapId,
								 Geometry::SRSPtr srs,
								 const std::string &outputPath) const override;

	virtual std::string MakeValidTableName(const std::string tableNameStump, const std::string & suffix = std::string("") , bool quoteTableName = true, int randomChars = 3 ) const;

	virtual std::string compute_histogram(const long& idgeo, const std::string& property, const std::string& ranges) const;

	virtual boost::shared_ptr<std::string> GetSimplexPropertiesAsCsv(const FeatureDesc & feature, long commitKey = -1) const;

	virtual std::string getSimplexPropertyValueAtXYZ(const long& idgeo, const double& x, const double& y, const double& z, const std::string& property) const;

	virtual std::string getLatestGeoJSONHullGeometry(const long& idgeo) const;

	virtual void deleteLatestGeometryHull(const long& idgeo) const;

	virtual long calculateConcaveHull(const long& idgeo) const;

	virtual long uploadLatestHullForGeometry(const std::string& file_path, const std::string& file_name, const Geometry::IFileSerialisable::FileType& file_type, const long & idgeo) const;

	virtual bool hasGeometryHull(const long &idgeo) const;

	virtual void CreateUser(const User& user, const std::string & initialgroupName);

	virtual void DropUser(const std::string & name);

	virtual void CreateGroup(const Group& group);

	virtual void DropGroup(const std::string & name);

	virtual UserListPtr GetAllGSTUsers() const;

	virtual GroupListPtr GetAllGSTGroups() const;

	virtual UserListPtr GetUsersByGroup(const std::string& groupName) const;

	virtual GroupListPtr GetGroupsByUser(const std::string& userName) const;

	virtual GroupListPtr GetGroupsByCurrentUser() const;

	virtual void AddUserToGroup(const std::string& userName, const std::string& groupName);

	virtual void DropUserFromGroup(const std::string& userName, const std::string& groupName);

    virtual void ChangeUserPassword(const std::string &userName,
                                    const std::string &newPassword,
                                    const std::string &oldPassword) const;
	virtual void ChangeUserPasswordAsAdmin(
		const User &user,
		const std::string &newPassword) const override;

	virtual std::string GetStorageRevision() const;

	virtual int CheckCompatibility(const std::string &client_version) const;

	virtual int CheckStorageLicense(const std::string &license, const std::string &version, std::string * errorMessage = NULL);

	virtual int CheckStorageModuleLicense(const Module &module, std::string *errorMessage = NULL, const std::string &version = "2.0");

	virtual Geometry::GSTSRSRefPtr InsertSRS(const Geometry::SRS & new_srs, const std::string & label, const std::string & code_type = std::string() , const std::string & code_value = std::string() );

	virtual void UpdateSRS(const Geometry::SRSItemVal & new_srs);

	virtual void DeleteSRS(const Geometry::GSTSRSRef & srsref);

	virtual Geometry::SRSItemDescListPtr ListAllSRS() const;

	virtual Geometry::SRSItemDescPtr GetSRSDetailByKey(long srsKey) const;

	virtual Geometry::SRSItemValPtr GetSRSDefinition(long srsKey) const;

	virtual void SetSRSForFeatureClass(const Geometry::GSTSRSRef & new_srs, const FeatureClassDesc & fclass);

	virtual void UnsetSRSForFeatureClass(const FeatureClassDesc & fclass);

	virtual void ChangeSRSForFeatureClass(const Geometry::GSTSRSRef & new_srs, const FeatureClassDesc & fclass);

	virtual std::string GetProj4ParamFromSRS(const Geometry::SRS &srs) const;

	virtual AccessLevelListPtr ListAccessLevels() const;

	virtual AccessLevelPtr GetAccessLevelById(long accessLevelId) const;

	virtual ServiceDescriptionPtr CreateService(const std::string &name, const std::string &url, long accessLevelId, const std::string &user, const std::string &secret) const;

	virtual ServiceDescriptionPtr GetServiceDescriptionById(long serviceId) const;

	virtual void DropService(long serviceId) const;

	virtual ServiceDescriptionPtr UpdateService(long serviceId, const std::string &name, const std::string &url, long accessLevelId, const std::string &user, const std::string &secret) const;

	virtual ServiceDescrionListPtr ListServices() const;

	virtual ServiceDescrionListPtr ListServicesByAccessLevel(long accessLevelId) const;

	virtual LevelListPtr GetLevels() const;

	virtual LinkAdjacencyListPtr GetChilds(LinkAdjacency::LinkId parent) const;

	virtual LinkAdjacencyListPtr GetParentsForFeature(LinkAdjacency::LinkId featureId) const;

	virtual AssignableElementListPtr GetElements(Owner::OwnerId owner, Level::LevelDepth levelId) const;

	virtual OwnerListPtr GetOwners() const;

	virtual OwnerListPtr GetAllOwners() const;

	virtual MoMaPropertyDescPtr CreateMoMaPropertyDesc(const std::string& name , TableAttributeDesc::DType dtype , Owner::OwnerId owner) const;

	virtual MoMaPropertyDescPtr GetMoMaPropertyDesc(MoMaPropertyDesc::PROPERTYID propertyid) const;

	virtual MoMaPropertyDescListPtr ListMoMaPropertyDesc() const;

	virtual void RenameMoMaPropertyDesc(const MoMaPropertyDesc::PROPERTYID propertyid, const std::string& newname) const;

	virtual void ChownMoMaPropertyDesc(const MoMaPropertyDesc::PROPERTYID propertyid, const long& newownerid) const;

	virtual void DeleteMoMaPropertyDesc(const MoMaPropertyDesc::PROPERTYID propertyid) const;

	virtual MoMaPropertyValuePtr CreateMoMaPropertyValue(LinkedElement& element, const MoMaPropertyDesc& desc, MoMaPropertyValue::PVALUE value) const;

	virtual void DeleteMoMaPropertyValue(const MoMaPropertyValue& value) const;

	virtual void SetMoMaPropertyValue(MoMaPropertyValue& value, MoMaPropertyValue::PVALUE newvalue) const;

	virtual MoMaPropertyValueListPtr ListMoMaPropertyValues(const LinkedElement& element) const;

	virtual MoMaPropertyValueListPtr ListMoMaPropertyValues(const MoMaPropertyDesc::PROPERTYID propertyid) const;

	virtual LinkAdjacencyPtr CreateLinkAdjacency(
		LinkAdjacency::LinkId parent,
		LinkAdjacency::ReferId refId,
		LinkAdjacency::TargetType refTarget,
		Owner::OwnerId owner) const override;

	virtual LinkAdjacencyPtr CreateLinkAdjacency(
		LinkAdjacency::LinkId parent,
		LinkAdjacency::ReferId refId,
		LinkAdjacency::TargetType refTarget,
		Owner::OwnerId owner,
		int64_t siblingRank) const override;

	void UpdateLinkAdjacencySiblingRank(LinkAdjacency::LinkId linkId,
										int64_t newSiblingRank) const override;

	virtual void DropLinkAdjacency(LinkAdjacency::LinkId linkId) const override;

	virtual void CreateElement(ElementPtr Element, bool uniqueName = false) const;

	virtual void RenameElement(ElementPtr Element, bool uniqueName = false) const;

	virtual void DropElement(Element::ElementId id) const;

	virtual ElementPtr ChownElement(const Element &element,
									const Owner &newOwner,
									const std::string &newName
									= std::string()) const override;

	virtual ColorScaleListPtr GetColorScales() const;

	virtual ColorValueListPtr GetColorValues(ColorScale::ColorScaleId colorscale) const;

	virtual ColorValuePtr GetColorValue(LinkAdjacency::LinkId lId, ColorScale::ColorScaleId cId) const;

	virtual ColorScale::ColorScaleId AddColorScale(ColorScalePtr cs) const;

	virtual ColorValue::ColorValueId AddColorValue(ColorValuePtr cv) const;

	virtual void DeleteColorScale(ColorScale::ColorScaleId csId) const;

	virtual void DeleteColorValue(ColorValue::ColorValueId cvId) const;

	virtual void AssignColorScale(ColorScale::ColorScaleId csID, Element::ElementId eId) const;

	virtual void AssignColorValue(ColorValue::ColorValueId cvId, LinkAdjacency::LinkId lId) const;

	virtual void UnAssignColorScale(ColorScale::ColorScaleId csID, Element::ElementId eId) const;

	virtual void UnAssignColorValue(ColorValue::ColorValueId cvId, LinkAdjacency::LinkId lId) const;

	virtual FeatureLinkIdGeometryIdPairListPtr ResolveGeometries(LinkAdjacency::LinkId rootElement, LinkAdjacency::LinkId csRootElement = ROOT_NODE_LINKID, ColorScale::ColorScaleId csRootScale = -1) const;

	virtual FeatureClassDescPtr ResolveFeatureClassFromGeometryId(const long & geometryId) const;

	virtual CrudeFeaturePtr GetFeatureFromMoMa(LinkAdjacency::LinkId flid , const Geometry::IGeometry::RequestFormat & geometryformat , Geometry::SRSPtr srs , LinkAdjacency::LinkId csRootElement = ROOT_NODE_LINKID , ColorScale::ColorScaleId csRootScale = -1 , bool lock = false , QueryBoxPtr queryBox = QueryBoxPtr() , long commitKey = -1) const;

	virtual QueryBoxPtr GetBboxFromMoma(const MoMaKey &momakey, Geometry::SRSPtr targetSrs) const;

	virtual GSTbox GetFeatureBboxTransformed(const FeatureDesc &fDesc, Geometry::SRSPtr targetSrs) const;

	virtual GSTbox GetBboxForFeaturesTransformed(std::vector<int64_t> featureIds, Geometry::SRSPtr targetSrs) const;

	virtual void ForceUnlinkGeometry(long geometryId);

	virtual void CreateUpdateDynamicColorScale(DynamicColorScalePtr dyncs);

	virtual void DropDynamicColorScale(const DynamicColorScale::ID & dyncs_id);

	virtual DynamicColorScaleListPtr ListDynamicColorScales() const;

	virtual DynamicColorScalePtr GetDynamicColorScale(const DynamicColorScale::ID & dyncs_id) const;

	virtual long BeginCommit(const std::string& message) const;

	virtual int EndCommit(long commitKey) const;

	virtual CommitListPtr ListCommits() const;

	virtual CommitListPtr ListCommitsByFeature(long geometryId);

	virtual CommitVersionListPtr ShowCommit(Commit::CommitKey key) const;

	virtual IntersectionInfoPtr SaveBoreholeImage(const BoreHoleImageParameters &boreholeParams, const OutputImageParameters &outputImageParams) const;

	virtual IntersectionInfoPtr SaveSectionImage(const SectionImageParameters &sectionParams, const OutputImageParameters &outputImageParams) const;

	virtual IntersectionInfoPtr SaveMapImage(const MapImageParameters &mapParams, const OutputImageParameters &outputImageParams) const;

	virtual std::string SaveBoreholeAsShapefileZip(const BoreHoleImageParameters &boreholeParams, const OutputShapeParameters &outputShapeParams) const;

	virtual std::string SaveSectionAsShapefileZip(const SectionImageParameters &sectionParams, const OutputShapeParameters &outputShapeParams) const;

	virtual std::string SaveMapAsShapefileZip(const MapImageParameters &mapParams, const OutputShapeParameters &outputShapeParams) const;

	IntersectionInfoPtr SaveBoreholeGridImage(
		const BoreholeGridImageParameters &boreholeParams,
		const OutputImageParameters &outputImageParams) const override;
	IntersectionInfoPtr SaveSectionGridImage(
		const SectionGridImageParameters &sectionParams,
		const OutputImageParameters &outputImageParams) const override;
	IntersectionInfoPtr SaveMapGridImage(
		const MapGridImageParameters &mapParams,
		const OutputImageParameters &outputImageParams) const override;

	ColorMap::Id CreateColorMap(
		const std::string &name,
		const ColorMapSegmentList &segments,
		const Geometry::IGeometry::Color &nodataColor,
		const std::string &regex,
		long accessLevelId,
		bool nodataTransparentForGrids = false) override;

	ColorMap::Id CreateDiscreteColorMap(
		const std::string &name,
		const ColorMapDiscreteValueList &values,
		const Geometry::IGeometry::Color &nodataColor,
		const std::string &regex,
		long accessLevelId,
		bool nodataTransparentForGrids = false) override;

	void UpdateColorMap(
		const ColorMap::Id &id,
		const std::string &name,
		const ColorMapSegmentList &segments,
		const Geometry::IGeometry::Color &nodataColor,
		const std::string &regex,
		long accessLevelId,
		bool nodataTransparentForGrids = false) override;

	void UpdateDiscreteColorMap(
		const ColorMap::Id &id,
		const std::string &name,
		const ColorMapDiscreteValueList &values,
		const Geometry::IGeometry::Color &nodataColor,
		const std::string &regex,
		long accessLevelId,
		bool nodataTransparentForGrids = false) override;

	virtual void DeleteColorMap(const ColorMap::Id & id);

	virtual ColorMapDescListPtr ListColorMaps() const;

	virtual ColorMapPtr GetColorMap(const ColorMap::Id & id) const;

	virtual void CreateRtreeIndex(long idgeo) const;

	virtual bool HasRtreeIndex(long idgeo) const;

	virtual void DropRtreeIndex(long idgeo) const;

	virtual PropertyAliasPtr GetObjectPropertyAlias(const ObjectPropertyDesc &opDesc) const;

	virtual PropertyAliasPtr GetSimplexPropertyAlias(const SimplexPropertyDesc &spDesc) const;

	virtual void CreateUpdateObjectPropertyAlias(const ObjectPropertyDesc &opDesc, const PropertyAlias &propertyAlias) const;

	virtual void CreateUpdateSimplexPropertyAlias(const SimplexPropertyDesc &spDesc, const PropertyAlias &propertyAlias) const;

	virtual void DropObjectPropertyAlias(const ObjectPropertyDesc &opDesc) const;

	virtual void DropSimplexPropertyAlias(const SimplexPropertyDesc &spDesc) const;

	virtual PropertyAliasMapPtr GetObjectPropertyAliasList(const FeatureClassDesc& featureClass) const;

	virtual PropertyAliasMapPtr GetSimplexPropertyAliasList(const FeatureClassDesc& featureClass) const;

    virtual LinkAdjacencyListPtr GetAllLinkAdjacencies() const;
    virtual LinkAdjacencyListPtr GetAllElementLinkAdjacencies() const;
    virtual LinkAdjacencyListPtr GetAllFeatureLinkAdjacencies() const;
    virtual ElementListPtr GetAllElements() const;
	virtual ElementListPtr GetModelsOfFeature(const FeatureDesc &feature) const;

    int64_t getLatestVersionForGeometry(const int64_t idgeo) const;


#ifdef WITH_GST_TESTS
	virtual void test_sproc(const Params &in, Params &out) const;
#endif // WITH_GST_TESTS

	virtual FeatureClassDescPtr CreateFeatureClass(const FeatureClassDetailedDesc& featureClassDesc);

	///@name LOD Handling
	//@{
	virtual AssignableFeatureDescListPtr GetLODs(const FeatureDesc & feature) const;
	virtual void AddLOD(const FeatureDesc & parentLevel, const FeatureDesc & fineLevel);
	virtual void RemoveLOD(const FeatureDesc & parentLevel, const FeatureDesc & fineLevel);
	//@}

	// web user handling
	virtual dbLogin loginWebUser(const webLogin &) const;
	virtual void createWebUser(const webLogin &,
							   const long &,
							   const char &,
							   const char &) const;
	virtual void updateWebUser(const std::string &oldName,
							   const std::string &newName,
							   const std::string &newPassword,
							   long newAccessLevel,
							   char newAllowUpload,
							   const char newAllowSHPSection) const;
	virtual void dropWebUser(const std::string &) const;
	virtual void mapWebToDbUser(const webLogin &, const dbLogin) const;
	virtual void removeWebFromDbUser(const webLogin &, const dbLogin) const;
	virtual WebuserDescListPtr listWebUsers() const;
	virtual webToDbMappingList listWebToDbUserMapping() const;

	struct SaveFeautreResult
	{
		std::string lock;
		std::string mainFileName;
		std::vector<std::string> fileNames;
		Geometry::SRSPtr srs;
	};
	SaveFeautreResult SaveFeatureStreamed(
		const std::string &path,
		const FeatureDesc &feature,
		const Geometry::IGeometry::RequestFormat &geometryformat,
		Geometry::SRSPtr srs,
		bool lock = false,
		QueryBoxPtr queryBox = QueryBoxPtr(),
		long commitKey = -1,
		boost::optional<std::vector<int64_t>> simplexPropertySelection
		= std::vector<int64_t>());
	SaveFeautreResult SaveFeatureStreamed(
		const std::string &path,
		const FeatureDesc &feature,
		const Geometry::IGeometry::RequestFormat &geometryformat,
		Geometry::SRSPtr srs,
		const boost::optional<AreaLimiter> &areaLimiter,
		bool lock = false,
		long commitKey = -1,
		boost::optional<std::vector<int64_t>> simplexPropertySelection
		= std::vector<int64_t>());
	FeatureDataList ListFeatureData(const FeatureClassDesc &featureClass) const;

	Utils::GSTVersionPtr
    GetStorageVersion() const;
#ifdef WITH_GST_TESTS
    void StartTesting() const;
#endif

    LinkedElementPtr GetLinkedElement(LinkAdjacency::LinkId nodelink_id) const;
    void ExtractGroupAndClassFromFeatureClassName( const std::string & featureClassName, std::string & groupName, std::string & className, bool & is_private );

protected:
	virtual void CreateFeatureClass_Impl(const FeatureClassDetailedDesc& featureClassDesc);
private:
	class Impl;
	Impl *m_impl;
};

struct GST_API_EXPORT GrpcRecordFeature : public CrudeFeature
{
	std::string geometry;
	std::string propertyDesc;
	std::string propertyVals;
	std::string lockid;
	TableAttributeValListPtr attributes;

	std::string GetGeometry() override
	{
		return geometry;
	}
	std::string GetPropertyDesc() override
	{
		return propertyDesc;
	}
	std::string GetPropertyVals() override
	{
		return propertyVals;
	}
	std::string GetLockId() override
	{
		return lockid;
	}
	TableAttributeValListPtr GetObjProperties() override
	{
		return attributes;
	}
};

} // namespace ClientUtils
} // namespace GST

#endif /* _GRPCACCESS_H_ */
